package com.wtwd.campus.h5_manager.service.impl;


import com.wtwd.campus.h5_manager.dao.H5ManageSysRolePermissionMapper;
import com.wtwd.campus.h5_manager.entity.vo.RolePermissionVo;
import com.wtwd.campus.h5_manager.service.H5MangerSysRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2022-03-04
 */
@Service
public class H5MangerSysRolePermissionServiceImpl implements H5MangerSysRolePermissionService {

    @Autowired
    private H5ManageSysRolePermissionMapper rolePermissionMapper;

    @Override
    public List<RolePermissionVo> getRolePermissionList(Integer roleId) {
        List<RolePermissionVo> rolePermissionList = rolePermissionMapper.getRolePermissionList(roleId);
        if (rolePermissionList != null && rolePermissionList.size() > 0) {
            rolePermissionList.stream().forEach(e -> {
                if (e.getCheckPermission() != null && e.getCheckPermission() != 0) {
                    e.setChecked(true);
                }else {
                    e.setChecked(false);
                }
            });
        }
        return rolePermissionList;
    }

    @Override
    public List<Integer> getRolePermissionPerIdByRoleId(Integer roleId) {
        return rolePermissionMapper.getRolePermissionPerIdByRoleId(roleId);
    }

    @Override
    public Integer bathAddRolePermission(Integer roleId, List<Integer> bathAddPermission) {
        return rolePermissionMapper.bathAddRolePermission(roleId,bathAddPermission);
    }

    @Override
    public Integer deleteByRoleId(Integer roleId) {
        return rolePermissionMapper.deleteByRoleId(roleId);
    }

    @Override
    public Integer deleteByRoleIdList(List<Integer> roleIdList) {
        return rolePermissionMapper.deleteByRoleIdList(roleIdList);
    }
}
